package gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Rectangle;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.Dimension;
import java.io.Console;

import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JRadioButton;
import javax.swing.JCheckBox;

import client.Client;






public class Report extends JFrame{
	
	static int f=6;
		
	final public static int DEFAULT_PORT = 5555;  
    private String host = MainPanel.ip; ;       
    int port=0;
	public static Client client1;
	static String[] answerString = new String[8];
	Object columnNames[];
	
	String str1, str2;
	
	boolean value1;
	boolean value2;
	boolean value3;
	boolean value4;
	boolean value5;
	boolean value6;
	
	

	
	private JPanel mainform = null;
	private MainPanel MP;
	private JLabel jLabelWelcome = null;
	private JButton jButtonExit = null;
	private JLabel jLabelLogIn = null;
	private JButton jButton1 = null;
	private JCheckBox jCheckBox1 = null;

	
	
	private JCheckBox jCheckBox2 = null;

	private JCheckBox jCheckBox3 = null;

	private JCheckBox jCheckBox4 = null;

	private JCheckBox jCheckBox5 = null;

	private JLabel jLabel = null;

	private JLabel jLabel1 = null;

	private JLabel jLabel2 = null;

	private JLabel jLabel3 = null;

	private JLabel jLabel4 = null;

	private JLabel jLabel5 = null;

	private JLabel jLabel6 = null;

	private JLabel jLabel7 = null;

	private JTextField jTextField = null;

	private JTextField jTextField1 = null;

	private JLabel jLabel8;

	private JLabel jLabel9;

	public Report() {
		super();
		initialize();
	}

	/**
	 * 
	 */
	private void initialize() {
		this.setSize(1000, 720);
		this.setContentPane(QuestionnareForm());
		this.setTitle("Questionnare");	
				
	}
	/**
	 * 
	 * @return
	 */
	private JPanel QuestionnareForm() {
		if (mainform == null) {
			ImageIcon welcome = new ImageIcon("report.gif");
			jLabelWelcome = new JLabel();
			jLabelWelcome.setBounds(new Rectangle(148, 43, 299, 85));
			jLabelWelcome.setIcon(welcome);
			
			
			jLabel9 = new JLabel();
			jLabel9.setBounds(new Rectangle(604, 306, 350, 24));
			jLabel9.setText("date:  x  x  /  x  x  /  x  x ");

			
			
			jLabel8 = new JLabel();
			jLabel8.setBounds(new Rectangle(604, 322, 350, 24));
			jLabel8.setText("          year    month   day");
			
			
			jLabel7 = new JLabel();
			jLabel7.setBounds(new Rectangle(524, 438, 38, 17));
			jLabel7.setText("to:");
			jLabel6 = new JLabel();
			jLabel6.setBounds(new Rectangle(525, 383, 63, 17));
			jLabel6.setText("from:");
			jLabel5 = new JLabel();
			jLabel5.setBounds(new Rectangle(604, 348, 350, 24));
			jLabel5.setText("        example: 11/06/20");
			jLabel4 = new JLabel();
			jLabel4.setBounds(new Rectangle(191, 420, 141, 17));
			jLabel4.setText("quantity items report");
			jLabel3 = new JLabel();
			jLabel3.setBounds(new Rectangle(189, 376, 112, 17));
			jLabel3.setText("satisfaction report");
			jLabel2 = new JLabel();
			jLabel2.setBounds(new Rectangle(189, 332, 199, 17));
			jLabel2.setText("costumer complaint status report");
			jLabel1 = new JLabel();
			jLabel1.setBounds(new Rectangle(189, 286, 86, 17));
			jLabel1.setText("orders report");
			jLabel = new JLabel();
			jLabel.setBounds(new Rectangle(188, 246, 200, 17));
			jLabel.setText("expenses for the quarter report");
			jLabelLogIn = new JLabel();
			jLabelLogIn.setBounds(new Rectangle(150, 196, 168, 35));
			jLabelLogIn.setText("check wanted reports");
			mainform = new JPanel();
			mainform.setLayout(null);
			mainform.setBackground(Color.CYAN); 
			mainform.add(getJButtonExit(), null);
			mainform.add(jLabelLogIn, null);
			mainform.add(getJButton1(), null);
			mainform.add(getJCheckBox1(), null);
			mainform.add(getJCheckBox2(), null);
			mainform.add(getJCheckBox3(), null);
			mainform.add(getJCheckBox4(), null);
			mainform.add(getJCheckBox5(), null);
			mainform.add(jLabel, null);
			mainform.add(jLabel1, null);
			mainform.add(jLabel2, null);
			mainform.add(jLabel3, null);
			mainform.add(jLabel4, null);
			mainform.add(jLabel5, null);
			mainform.add(jLabel6, null);
			mainform.add(jLabel7, null);
			mainform.add(jLabel8, null);
			mainform.add(jLabel9, null);
			
			
			mainform.add(getJTextField(), null);
			mainform.add(getJTextField1(), null);
			mainform.add(jLabelWelcome, null);
		}
		return mainform; 
	}

/**
 * @return
 */
	private JButton getJButtonExit() {
		if (jButtonExit == null) {
			jButtonExit = new JButton();
			jButtonExit.setBounds(new Rectangle(794, 520, 155, 64));
			jButtonExit.setText("back");
			jButtonExit.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					
					MainEmployee MFrame = new MainEmployee();
				    MFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
				    MFrame.setSize( 1000,720 ); // set frame size
				    MFrame.setResizable(true);
				    MFrame.setVisible( true ); // display frame								    
				    Client.aFrame.dispose();   
				    
				}
			});
		}
		return jButtonExit;
	}

	/**
	 * This method initializes jButton1	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton1() 
	{
		if (jButton1 == null) {
			jButton1 = new JButton();
			jButton1.setBounds(new Rectangle(26, 520, 158, 64));
			jButton1.setText("next");
			
		
			
			
			jButton1.addActionListener(new java.awt.event.ActionListener() 
			{
				public void actionPerformed(java.awt.event.ActionEvent e) 
				{
					
					answerString[0]="report";
					
				
					value1=jCheckBox1.isSelected();
					value2=jCheckBox2.isSelected();
					value3=jCheckBox3.isSelected();
					value4=jCheckBox4.isSelected();
					value5=jCheckBox5.isSelected();
					
					answerString[1]=Integer.toString(value1 ? 1 : 0 );		
					answerString[2]=Integer.toString(value2 ? 1 : 0 );						
					answerString[3]=Integer.toString(value3 ? 1 : 0 );						
					answerString[4]=Integer.toString(value4 ? 1 : 0 );	
					answerString[5]=Integer.toString(value5 ? 1 : 0 );		
					
					answerString[6]=jTextField.getText();
					answerString[7]=jTextField1.getText();
					
					System.out.println(answerString[0]);
					System.out.println(answerString[1]);
					System.out.println(answerString[2]);
					System.out.println(answerString[3]);
					System.out.println(answerString[4]);
					System.out.println(answerString[5]);
			
					System.out.println(answerString[6]);
					System.out.println(answerString[7]);
									
					int my_error=0;				

					int v1,v2,v3,v4,v5;
					v1=(value1 ? 1 : 0 );
					v2=(value2 ? 1 : 0 );
					v3=(value3 ? 1 : 0 );
					v4=(value4 ? 1 : 0 );
					v5=(value5 ? 1 : 0 );
					int vsum=v1+v2+v3+v4+v5;
					if(vsum!=1)
					{
						ErrorFrame EFrame = new ErrorFrame();
						EFrame.jLabelMassage.setText("PLEASE check only one");
						EFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
						EFrame.setSize( 380,217 ); // set frame size
						EFrame.setResizable(true);
						EFrame.setVisible( true );
					}
					else
					{
						
//----------------------------------------start with date----------------------------						
						if(value2||value3)
						{
						
							String from1 = answerString[6];						
							String from2 = answerString[7];	
							
							if(from1.length()!=8)
								from1="00000000";
							if(from2.length()!=8)
								from2="00000000";	
																				
								char ch;
								int err = 0;
												
								ch=from1.toCharArray()[0];
								if((ch<'0')||(ch>'9'))
									err=1;
								ch=from1.toCharArray()[1];
								if((ch<'0')||(ch>'9'))
									err=1;
								ch=from1.toCharArray()[2];
								if(ch!='/')
									err=1;
								ch=from1.toCharArray()[3];
								if((ch<'0')||(ch>'9'))
									err=1;
								ch=from1.toCharArray()[4];
								if((ch<'0')||(ch>'9'))
									err=1;
								ch=from1.toCharArray()[5];
								if(ch!='/')
									err=1;
								ch=from1.toCharArray()[6];
								if((ch<'0')||(ch>'9'))
									err=1;
								ch=from1.toCharArray()[7];
								if((ch<'0')||(ch>'9'))
									err=1;						
								
								
								
								ch=from2.toCharArray()[0];
								if((ch<'0')||(ch>'9'))
									err=1;
								ch=from2.toCharArray()[1];
								if((ch<'0')||(ch>'9'))
									err=1;
								ch=from2.toCharArray()[2];
								if(ch!='/')
									err=1;
								ch=from2.toCharArray()[3];
								if((ch<'0')||(ch>'9'))
									err=1;
								ch=from2.toCharArray()[4];
								if((ch<'0')||(ch>'9'))
									err=1;
								ch=from2.toCharArray()[5];
								if(ch!='/')
									err=1;
								ch=from2.toCharArray()[6];
								if((ch<'0')||(ch>'9'))
									err=1;
								ch=from2.toCharArray()[7];
								if((ch<'0')||(ch>'9'))
									err=1;
						
								
								if(err==0)
								{
									Client clientReport = new Client(host,DEFAULT_PORT);
									clientReport.accept(answerString);
									Object b = clientReport.getMsg();			
									int a;


									if(answerString[5].toCharArray()[0]=='1')
									{
										columnNames = new Object[]{ "item", "quantity" };
										MyTable Tb = new MyTable((Object[][]) b,columnNames);
										Tb.setTitle("Quantity Report");
									}				
						
									if(answerString[2].toCharArray()[0]=='1')
									{
				
										columnNames = new Object[]{ "order number", "date" };
										MyTable Tb = new MyTable((Object[][]) b,columnNames);
										Tb.setTitle("Orders Report");
									}
							
									if(answerString[3].toCharArray()[0]=='1')
									{
										columnNames = new Object[]{ "complaint number", "date" };
										MyTable Tb = new MyTable((Object[][]) b,columnNames);
										Tb.setTitle("Orders Report");
									}
							
									if(answerString[4].toCharArray()[0]=='1')
									{
										columnNames = new Object[]{ "survey number", "average grade" };
										MyTable Tb = new MyTable((Object[][]) b,columnNames);
										Tb.setTitle("satisfaction report");
									}
							
							
									if(answerString[1].toCharArray()[0]=='1')
									{
										columnNames = new Object[]{ "order number", "date(3 months)" , "price"};
										MyTable Tb = new MyTable((Object[][]) b,columnNames);
										Tb.setTitle("expenses for the quarter report");
									}	
								}
								else
								{
									
									ErrorFrame EFrame2 = new ErrorFrame();
									EFrame2.jLabelMassage.setText("wrong input date");
									EFrame2.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
									EFrame2.setSize( 380,217 ); // set frame size
									EFrame2.setResizable(true);
									EFrame2.setVisible( true ); 
									
								}
						

							
				
						}
	
	//-------------------------------------------end with date-----------------------					
						
						
						
						
						
						
						
						
						
						
						
						
						
	//--------------------------------------------start without date----------------------					
					if(value1||value4||value5)
					{
						///////////////////////////////////////////////
							
						Client clientReport = new Client(host,DEFAULT_PORT);
						clientReport.accept(answerString);
						Object b = clientReport.getMsg();			
						int a;


						if(answerString[5].toCharArray()[0]=='1')
						{
							columnNames = new Object[]{ "item", "quantity" };
							MyTable Tb = new MyTable((Object[][]) b,columnNames);
							Tb.setTitle("Quantity Report");
						}				
					
						if(answerString[2].toCharArray()[0]=='1')
						{
			
							columnNames = new Object[]{ "order number", "date" };
							MyTable Tb = new MyTable((Object[][]) b,columnNames);
							Tb.setTitle("Orders Report");
						}
					
						if(answerString[3].toCharArray()[0]=='1')
						{
							columnNames = new Object[]{ "complaint number", "date" };
							MyTable Tb = new MyTable((Object[][]) b,columnNames);
							Tb.setTitle("Orders Report");
						}
						
						if(answerString[4].toCharArray()[0]=='1')
						{
							columnNames = new Object[]{ "survey number", "average grade" };
							MyTable Tb = new MyTable((Object[][]) b,columnNames);
							Tb.setTitle("satisfaction report");
						}
							
							
						if(answerString[1].toCharArray()[0]=='1')
						{
							columnNames = new Object[]{ "order number", "date(3 months)" , "price"};
							MyTable Tb = new MyTable((Object[][]) b,columnNames);
							Tb.setTitle("expenses for the quarter report");
						}
							
							
					}
						
	//----------------------------------------------end without date--------------------------
						
						
					}
							
							
							
							
							
				
						
				}
			}			
					
		
		
			);
		}
			
			
			
		


		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		return jButton1;
	}

	/**
	 * This method initializes jComboBox	
	 * 	
	 * @return javax.swing.JComboBox	
	 */


	/**
	 * This method initializes jCheckBox1	
	 * 	
	 * @return javax.swing.JCheckBox	
	 */
	private JCheckBox getJCheckBox1() {
		if (jCheckBox2 == null) {	
			jCheckBox1 = new JCheckBox();
			jCheckBox1.setBounds(new Rectangle(156, 244, 21, 21));
		}
		return jCheckBox1;
	}

	/**
	 * This method initializes jCheckBox2	
	 * 	
	 * @return javax.swing.JCheckBox	
	 */
	private JCheckBox getJCheckBox2() {
		if (jCheckBox2 == null) {
			jCheckBox2 = new JCheckBox();
			jCheckBox2.setBounds(new Rectangle(156, 286, 21, 21));
		}
		return jCheckBox2;
	}

	/**
	 * This method initializes jCheckBox3	
	 * 	
	 * @return javax.swing.JCheckBox	
	 */
	private JCheckBox getJCheckBox3() {
		if (jCheckBox3 == null) {
			jCheckBox3 = new JCheckBox();
			jCheckBox3.setBounds(new Rectangle(157, 329, 21, 21));
		}
		return jCheckBox3;
	}

	/**
	 * This method initializes jCheckBox4	
	 * 	
	 * @return javax.swing.JCheckBox	
	 */
	private JCheckBox getJCheckBox4() {
		if (jCheckBox4 == null) {
			jCheckBox4 = new JCheckBox();
			jCheckBox4.setBounds(new Rectangle(157, 375, 21, 21));
		}
		return jCheckBox4;
	}

	/**
	 * This method initializes jCheckBox5	
	 * 	
	 * @return javax.swing.JCheckBox	
	 */
	private JCheckBox getJCheckBox5() {
		if (jCheckBox5 == null) {
			jCheckBox5 = new JCheckBox();
			jCheckBox5.setBounds(new Rectangle(156, 418, 21, 21));
		}
		return jCheckBox5;
	}

	/**
	 * This method initializes jTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField() {
		if (jTextField == null) {
			jTextField = new JTextField();
			jTextField.setBounds(new Rectangle(627, 382, 116, 21));
		}
		return jTextField;
	}

	/**
	 * This method initializes jTextField1	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField1() {
		if (jTextField1 == null) {
			jTextField1 = new JTextField();
			jTextField1.setBounds(new Rectangle(630, 435, 103, 21));
		}
		return jTextField1;
	}

	
	
}  //  @jve:decl-index=0:visual-constraint="26,28"
